package com.symbio.ishenapi.background.controller;


import com.symbio.ishenapi.background.model.TmInsureRecord;
import com.symbio.ishenapi.common.controller.BaseController;
import io.jboot.web.controller.annotation.RequestMapping;

import java.util.*;

@RequestMapping("tmInsureRecordController")
public class TmInsureRecordController extends BaseController {


    /**
     * 查询投保记录
     *
     */
    public void findAll(){
        List<TmInsureRecord> list = TmInsureRecord.dao.findAll();
        if(list == null && list.size() == 0){
            list = new ArrayList<>();
        }
        renderJson(list);

    }


    /**
     * 保存投保记录
     */
    public void save(){
        //System.out.println("===="+getReqBodyString());
        Map<String,Object> map = new HashMap<>();
        TmInsureRecord tmInsureRecord = (TmInsureRecord)getReqBodyObject(TmInsureRecord.class);
        System.out.println("===="+tmInsureRecord);

        if(tmInsureRecord.getName() == null && "".equals(tmInsureRecord.getName())){
            renderError(40003,"用户名");
            return;
        }
        if(tmInsureRecord.getSequenceId() == null && "".equals(tmInsureRecord.getSequenceId())){
            renderError(40003,"流水号");
            return;
        }
        if(tmInsureRecord.getToken() == null && "".equals(tmInsureRecord.getToken())){
            renderError(40003,"token");
            return;
        }
        if(tmInsureRecord.getInsurationuser() == null && "".equals(tmInsureRecord.getInsurationuser())){
            renderError(40003,"保险用户名");
            return;
        }
        if(tmInsureRecord.getIdtype() == null && "".equals(tmInsureRecord.getIdtype())){
            renderError(40003,"投保人证件类型");
            return;
        }
        if(tmInsureRecord.getIdc() == null && "".equals(tmInsureRecord.getIdc())){
            renderError(40003,"投保人证件号码");
            return;
        }
        if(tmInsureRecord.getSex() == null && "".equals(tmInsureRecord.getSex())){
            renderError(40003,"投保人性别");
            return;
        }
        if(tmInsureRecord.getTele() == null && "".equals(tmInsureRecord.getTele())){
            renderError(40003,"投保电话");
            return;
        }
        if(tmInsureRecord.getItype() == null && "".equals(tmInsureRecord.getItype())){
            renderError(40003,"投保类型（险种）");
            return;
        }
        if(tmInsureRecord.getStarttime() == null && "".equals(tmInsureRecord.getStarttime())){
            renderError(40003,"开始时间");
            return;
        }
        if(tmInsureRecord.getEndtime() == null && "".equals(tmInsureRecord.getEndtime())){
            renderError(40003,"结束时间");
            return;
        }
        if(tmInsureRecord.getResult() == null && "".equals(tmInsureRecord.getResult())){
            renderError(40003,"结果");
            return;
        }
        tmInsureRecord.setCreateTime(new Date());

       if(tmInsureRecord.save()){
            map.put("sequence_id",tmInsureRecord.getSequenceId());
            map.put("code",000);
            map.put("message","请求成功");
            renderJson(map);
            return;
        }else{
            renderJsonError(40003,"投保记录");
            return;
        }
    }
}
